package cn.domypay.back.thread;

import cn.domypay.back.bean.DmpOrderInfo;
import cn.domypay.back.control.OrderControl;
import cn.domypay.back.exception.DoMyPayException;
import cn.domypay.back.log.DoMyPayLogger;

public class OrderThread extends Thread{
	
	private final static DoMyPayLogger logger = DoMyPayLogger.getLogger(OrderThread.class);
	
	private OrderControl orderControl;
	private DmpOrderInfo dmpOrderInfo;
	
	private static boolean IS_RUN = true;  //是否运行线程:默认是运行
	
	public OrderThread()
	{	}
	
	public OrderThread(OrderControl orderControl, DmpOrderInfo dmpOrderInfo)
	{
		this.orderControl = orderControl;
		this.dmpOrderInfo = dmpOrderInfo;
	}
	
	public OrderThread(ThreadGroup group, String name, OrderControl orderControl, DmpOrderInfo dmpOrderInfo)
	{
		super(group, name);
		this.orderControl = orderControl;
		this.dmpOrderInfo = dmpOrderInfo;
	}
	
	/**
	 * 线程处理控制订单处理
	 */
	public void run()
	{
		//如果订单处理成功
		try {
			if(this.orderControl.dealPerPaid(dmpOrderInfo))
			{
				//修改订单处理状态
				orderControl.modityOrderStatus(dmpOrderInfo);
			}
		} catch (DoMyPayException e) {
			// TODO 自动生成 catch 块
			logger.logError("OrderERROR:["+e.getMessage()+"]");
			this.interrupt();
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			logger.logError("OrderERROR:["+e.getMessage()+"]");
			this.interrupt();
		}
	}
	
	/**
	 * 暂停订单处理线程
	 * @return
	 */
	public void orderStop()
	{ 
		IS_RUN = false;
	}
	
}
